package com.myapp.model.impl.product;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import com.myapp.model.dao.product.ProductDao;
import com.myapp.model.entity.product.Product;

public class ProductDaoImpl implements ProductDao {
	
	private SqlSessionTemplate sqlDao;
	
	@Override
	public Product addProduct(Product prod) {
		sqlDao.insert("product.addProduct", prod);
		return prod;
	}
	
	@SuppressWarnings("unchecked")
	public List<Product> getLatestProducts(){
		return (List<Product>)sqlDao.selectList("product.selectProduct");
	}

	public void setSqlDao(SqlSessionTemplate sqlDao) {
		this.sqlDao = sqlDao;
	}

	@Override
	public Product getProduct(int prodId) {
		return (Product)sqlDao.selectOne("product.selectOneProduct",new Integer(prodId));
	}
}
